package com.gimi.cloud.bbp.client.service.order.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.domain.AlipayTradeAppPayModel;
import com.alipay.api.request.AlipayTradeAppPayRequest;
import com.alipay.api.response.AlipayTradeAppPayResponse;
import com.gimi.cloud.bbp.client.service.order.PayService;
import com.gimi.cloud.bbp.common.constant.RedisKeyConstant;
import com.gimi.cloud.bbp.commonService.alipay.AliPayService;
import com.gimi.cloud.bbp.commonService.redis.RedisService;

/**
 * 支付服务
 * @author 李林峰
 * @version 1.0
 * @Description
 * @create 2018年2月2日
 */
@Service
public class PayServiceImpl implements PayService {
	@Autowired AliPayService aliPayService;
	@Autowired RedisService redisService;

	@Override
	public String getAliPayOrderString(AlipayTradeAppPayModel model) throws AlipayApiException {
		JSONObject aliPayConfig = redisService.getJSONObjectConfigByKey(RedisKeyConstant.ALI_PAY_CONFIG);
		//实例化客户端
		AlipayClient alipayClient = aliPayService.creatAlipayClient();
		//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称：alipay.trade.app.pay
		AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
		request.setBizModel(model);
		request.setNotifyUrl(aliPayConfig.getString("notifyUrl"));
		AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request);
	    return response.getBody();
	}
	
}